﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DTO;

namespace DAO
{
    public class NguoiDungDAO
    {
        DataProvider cmd = new DataProvider();
        SqlDataReader dr;
        public string TinhTrang(string user)
        {
            dr = cmd.dataReader("select * from  NguoiDung where Username = '" + user + "'");
            dr.Read();
            string a = dr["TinhTrang"].ToString();
            dr.Close();
            return a;
        }
        public bool KiemTraUserPass(string user, string pass)
        {
            dr = cmd.dataReader("select * from  NguoiDung where Username = '" + user + "' and Password =  '" + pass + "'");
            while (dr.Read())
            {
                dr.Close();
                return true;
            }
            dr.Close();
            return false;
        }
        public SqlDataReader DataNguoiDung(string user)
        {
            return cmd.dataReader("select * from NguoiDung where Username = '" + user + "'");
        }
        public SqlDataReader Datafull()
        {
            return cmd.dataReader("select * from NguoiDung");
        }

        public void updatepass(string paw, string user)
        {
            cmd.ExeCuteNonQuery(@"update NguoiDung set Password = '" + paw + "' where UserName = '" + user + "'");
        }
        public DataTable GetData()
        {
            return cmd.GetData(@"select  HoTen, CMND, NgaySinh, GioiTinh, DiaChi, DienThoai,
                                ChucVu, Username, Password, TinhTrang
                                from NguoiDung");
        }
        public bool KiemTraUser(string user)
        {
            dr = cmd.dataReader("select * from  NguoiDung");
            while (dr.Read())
            {
                if (dr["Username"].ToString() == user)
                {
                    dr.Close();
                    return false;
                }
            }
            dr.Close();
            return true;
        }

        public void delete(string user)
        {
            cmd.ExeCuteNonQuery("delete NguoiDung where UserName = N'" + user + "'");
        }
        public DataTable GetDataUser(string user)
        {
            return cmd.GetData("select * from NguoiDung where HoTen = N'" + user + "'");
        }

        public string mail(string user)
        {
            dr = cmd.dataReader("select * from NguoiDung where Username = N'" + user + "'");
            dr.Read();
            string a = dr["Email"].ToString();
            dr.Close();
            return a;
        }
    }
}
